package com.iconmaker.command;

import java.util.Stack;

public class CommandManager {
	
	private static Stack<ICommand> commandDoHistory = new Stack<ICommand>();
	private static Stack<ICommand> commandUndoHistory = new Stack<ICommand>();
	
	public static void doCommand(ICommand command) {
		if(command.doCommand())
			commandDoHistory.push(command);
	}
	
	public static void unDo() {
		if(!commandDoHistory.isEmpty()) {
			ICommand pop = commandDoHistory.pop();
			pop.unDoCommand();
			commandUndoHistory.push(pop);
		}
	}
	
	public static void reDo() {
		if(!commandUndoHistory.isEmpty()) {
			ICommand pop = commandUndoHistory.pop();
			pop.doCommand();
			commandDoHistory.push(pop);
		}
	}
	
	public static void clear() {
		commandDoHistory = new Stack<ICommand>();
		commandUndoHistory = new Stack<ICommand>();
	}
}
